package cn.com.petrochina.lpm3.util;

import cn.com.petrochina.lpm3.vo.mdm.Query;
import cn.com.petrochina.lpm3.vo.mdm.RequestBody;
import cn.com.petrochina.lpm3.vo.mdm.ResponseBody;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

public class MDMUtil {
    //国家地区代码
    public static final String urlCountryCode = "https://10.30.160.36:44300/RESTAdapter/MDM/TY038/A2";

    //省直辖市代码
    public static final String urlProvinceCode = "https://10.30.160.36:44300/RESTAdapter/MDM/TY040/A2";

    //城市代码
    public static final String urlCityCode = "https://10.30.160.36:44300/RESTAdapter/MDM/TY037/A2";

    public static ResponseBody getCountryCode() {

        Query.QueryCountry queryCountry = new Query.QueryCountry();
        queryCountry.setCodeQuery("CN");
        queryCountry.setTextCNQuery("中国");

        HttpHeaders headers = new HttpHeaders();
        headers.setBasicAuth("ESB_A2", "uMXGJW!3EW&7&t2");

        RequestBody req = new RequestBody(new RequestBody.TechInfo("A2202403181212000001", "202403181212", null), new RequestBody.QueryDATA(queryCountry));

        RestTemplate restTemplate = new RestTemplate(new HttpsClientRequestFactory());
//        ResponseEntity<Object> post = RestTemplateUtils.post(urlCountryCode,headers, req, Object.class);
        HttpEntity<Object> requestEntity = new HttpEntity(req, headers);
        ResponseEntity<ResponseBody> post = restTemplate.exchange(urlCountryCode, HttpMethod.POST, requestEntity, ResponseBody.class);
        return post.getBody();
    }

//    public static ResponseBody getCountryCodeByMap() {
//        Map data = new HashMap<String, Object>() {{
//            put("Query", new HashMap<String, String>() {{
//                put("AccessType","MDM");
//                put("AccessKey","C6BDF6F65F3845DA9085E9AE5790B494");
//                put("QueryType","Z001");
//                put("Start_Rows","0");
//                put("Fetch_Rows","0");
//                put("CodeQuery","CN");
//                put("TextCNQuery","中国");
//                put("TextENQuery","");
//            }});
//
//        }};
//
//        HttpHeaders headers = new HttpHeaders();
//        headers.setBasicAuth("ESB_A2", "uMXGJW!3EW&7&t2");
//
//        RequestBody req = new RequestBody(new RequestBody.TechInfo("A2202403181212000001", "202403181212",null), data);
//
//        RestTemplate restTemplate = new RestTemplate(new HttpsClientRequestFactory());
////        ResponseEntity<Object> post = RestTemplateUtils.post(urlCountryCode,headers, req, Object.class);
//        HttpEntity<Object> requestEntity = new HttpEntity(req, headers);
//        ResponseEntity<ResponseBody> post = restTemplate.exchange(urlCountryCode, HttpMethod.POST, requestEntity, ResponseBody.class);
//        return post.getBody();
//    }


}
